from django.db import models

# Create your models here.

class Author(models.Model):
    gender_choices = (
        (1, "男"),
        (2, "女"),
        (3, "保密"),
    )
    # 姓名
    name = models.CharField(max_length=32)
    # 年龄
    age = models.IntegerField()
    # 性别
    gender = models.IntegerField(choices=gender_choices)
    # 创建一对一的外键关系
    author_detail = models.OneToOneField(to="AuthorDetail", on_delete=models.CASCADE)

    class Meta():
        db_table = "author"
        verbose_name_plural = "作者表"

    def __str__(self):
        return f"这是 {self.name} 作者对象!"


class AuthorDetail(models.Model):
    # 正常的 IntegerField 不能支持到11长度
    # 手机号
    phone = models.BigIntegerField()
    # 邮箱
    email = models.EmailField()
    # 地址
    addr = models.CharField(max_length=255)

    class Meta():
        db_table = "author_detail"
        verbose_name_plural = "作者详情表"